﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public static Player Instance;

    public SpriteRenderer sp;
    public ColorType colorType;

    void Awake()
    {
        Instance = this;
    }

    void Start()
    {

        ShuaiFunction.Refresh(sp, colorType);
    }

    public void ChangeType(int changeNumber)
    {
        colorType += changeNumber;

        if (Convert.ToInt32(colorType) > Convert.ToInt32(ColorType.blue))
        {
            colorType = ColorType.red;
        }
        if (Convert.ToInt32(colorType) < Convert.ToInt32(ColorType.red))
        {
            colorType = ColorType.blue;
        }

        ShuaiFunction.Refresh(sp, colorType);
    }


    void Update()
    {
        
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log(collision);
        if (collision)
        {
            Ball ball = collision.GetComponent<Ball>();
            if (ball.colorType == this.colorType)
            {
                Debug.Log("111");

                GameManager.Instance.socre++;
                UIManager.Instance.Text_score.text = GameManager.Instance.socre.ToString();
            }
            else
            {
                Debug.Log("222");

                GameManager.Instance.socre--;
                UIManager.Instance.Text_score.text = GameManager.Instance.socre.ToString();
            }

            Destroy(collision.gameObject);
        }
    }
}
